package org.changchen.fgt.constant;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

import org.springframework.util.StringUtils;

/**   
* @ClassName:  FromCodeEnum   
* @Description:采集资源展示颜色枚举   
* @author:     ChangChen 
* @date:       2024-03-22 09:35
* @Copyright:  2024 ChangChen. All rights reserved. 
*/
public enum FromCodeColorEnum {

	
	yellow,
	
	red,
	
	green,
	
	blue,
	
	brown,
	
	purple;
	
	
	private static Map<String,String> CODE_MAP = new HashMap<>();
	
	
	/**   
	 * @Title:      getColor   
	 * @Description:获取对应颜色   
	 * @param:      @param code
	 * @param:      @return      
	 * @return:     String      
	 * @throws   
	 */
	public static String getColor(String code) {
		
		String color = CODE_MAP.get(code);
		if(StringUtils.isEmpty(color)) {
			color = randomColor();
			CODE_MAP.put(code, color);
		}
		
		return color;	
	}
	
	
	private static String randomColor() {
		Random random=new Random();
		return FromCodeColorEnum.values()[random.nextInt(FromCodeColorEnum.values().length)] + "";
	}
	
}
